package com.hjimi.ski.view.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hjimi.ski.R;
import com.hjimi.ski.config.Constant;
import com.hjimi.ski.utils.SpUtil;


/**
 * Created By 孙岩
 * on 2023/2/3
 */
public class SettingDialog extends BaseDialog implements View.OnFocusChangeListener {
    private Context context;
    private RelativeLayout rlShowDetailCode;
    private ImageView tvIcon;
    private RelativeLayout rlHideDetailCode;
    private ImageView tvIcon1;
    private RelativeLayout rlImageStatic;
    private ImageView tvIcon2;
    private RelativeLayout rlImageLoop;
    private ImageView tvIcon3;
    private RelativeLayout rlVideoStatic;
    private ImageView tvIcon4;
    private RelativeLayout rlVideoLoop;
    private ImageView tvIcon5;
    private TextView tvShow;
    private TextView tvHide;
    private TextView tvImageStatic;
    private TextView tvImageLoop;
    private TextView tvVideoStatic;
    private TextView tvVideoLoop;
    private boolean isCheck = false;
    private IMode iMode;


    public SettingDialog(@NonNull Context context) {
        super(context);

    }

    public SettingDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
        initData();
    }

    protected SettingDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    private void initView() {
        LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(getOwnerActivity().LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.pupup_setting,
                null);
        rlShowDetailCode = (RelativeLayout) view.findViewById(R.id.rlShowDetailCode);
        rlHideDetailCode = (RelativeLayout) view.findViewById(R.id.rlHideDetailCode);
        rlImageStatic = (RelativeLayout) view.findViewById(R.id.rlImageStatic);
        rlImageLoop = (RelativeLayout) view.findViewById(R.id.rlImageLoop);
        rlVideoStatic = (RelativeLayout) view.findViewById(R.id.rlVideoStatic);
        rlVideoLoop = (RelativeLayout) view.findViewById(R.id.rlVideoLoop);

        tvIcon = (ImageView) view.findViewById(R.id.tvIcon);
        tvIcon1 = (ImageView) view.findViewById(R.id.tvIcon1);
        tvIcon2 = (ImageView) view.findViewById(R.id.tvIcon2);
        tvIcon3 = (ImageView) view.findViewById(R.id.tvIcon3);
        tvIcon4 = (ImageView) view.findViewById(R.id.tvIcon4);
        tvIcon5 = (ImageView) view.findViewById(R.id.tvIcon5);

        tvShow = (TextView) view.findViewById(R.id.tvShow);
        tvHide = (TextView) view.findViewById(R.id.tvHide);
        tvImageStatic = (TextView) view.findViewById(R.id.tvImageStatic);
        tvImageLoop = (TextView) view.findViewById(R.id.tvImageLoop);
        tvVideoStatic = (TextView) view.findViewById(R.id.tvVideoStatic);
        tvVideoLoop = (TextView) view.findViewById(R.id.tvVideoLoop);

        rlShowDetailCode.setOnFocusChangeListener(this);
        rlHideDetailCode.setOnFocusChangeListener(this);
        rlImageStatic.setOnFocusChangeListener(this);
        rlImageLoop.setOnFocusChangeListener(this);
        rlVideoStatic.setOnFocusChangeListener(this);
        rlVideoLoop.setOnFocusChangeListener(this);

        setContentView(view);
        getWindow().setGravity(Gravity.TOP);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);
    }

    private void initData() {
        if (SpUtil.getInstance(context).getBoolean(Constant.CODE_DETAIL, false)) {
            rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
            tvIcon.setVisibility(View.GONE);
            tvHide.setTextColor(context.getResources().getColor(R.color.stage_white));

            rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
            tvIcon1.setVisibility(View.VISIBLE);
            tvIcon1.setImageResource(R.mipmap.set_select_y);
            tvShow.setTextColor(context.getResources().getColor(R.color.stage_main));
        } else {
            rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting_select);
            tvIcon.setVisibility(View.VISIBLE);
            tvIcon.setImageResource(R.mipmap.set_select_w);
            tvHide.setTextColor(context.getResources().getColor(R.color.stage_white));

            rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
            tvIcon1.setVisibility(View.GONE);
            tvShow.setTextColor(context.getResources().getColor(R.color.stage_white));
        }

        if(SpUtil.getInstance(context).getBoolean(Constant.IMG_IS_LOOP,false)){
            rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
            tvIcon3.setVisibility(View.VISIBLE);
            tvIcon3.setImageResource(R.mipmap.set_select_y);
            tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_main));

            rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
            tvIcon2.setVisibility(View.GONE);
            tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_white));
        }else{
            rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
            tvIcon2.setVisibility(View.VISIBLE);
            tvIcon2.setImageResource(R.mipmap.set_select_y);
            tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

            rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
            tvIcon3.setVisibility(View.GONE);
            tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
        }

        if(SpUtil.getInstance(context).getBoolean(Constant.VIDEO_IS_LOOP,false)){
            rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
            tvIcon5.setVisibility(View.VISIBLE);
            tvIcon5.setImageResource(R.mipmap.set_select_y);
            tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_main));

            rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
            tvIcon4.setVisibility(View.GONE);
            tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_white));
        }else{
            rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
            tvIcon4.setVisibility(View.VISIBLE);
            tvIcon4.setImageResource(R.mipmap.set_select_y);
            tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

            rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
            tvIcon5.setVisibility(View.GONE);
            tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
        }

    }

    public void setModeListener(IMode iMode) {
        this.iMode = iMode;
    }

    @Override
    public void onFocusChange(View view, boolean b) {
        if (view.getId() == R.id.rlHideDetailCode) {

            if (SpUtil.getInstance(context).getBoolean(Constant.CODE_DETAIL, false)) {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon.setVisibility(View.GONE);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.VISIBLE);
                tvIcon1.setImageResource(R.mipmap.set_select_y);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_main));
            } else {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon.setVisibility(View.VISIBLE);
                tvIcon.setImageResource(R.mipmap.set_select_w);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.GONE);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.IMG_IS_LOOP,false)){
                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.VISIBLE);
                tvIcon3.setImageResource(R.mipmap.set_select_y);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.GONE);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_white));
            }else{
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.VISIBLE);
                tvIcon2.setImageResource(R.mipmap.set_select_y);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.GONE);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.VIDEO_IS_LOOP,false)){
                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.VISIBLE);
                tvIcon5.setImageResource(R.mipmap.set_select_y);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.GONE);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_white));
            }else{
                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.VISIBLE);
                tvIcon4.setImageResource(R.mipmap.set_select_y);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.GONE);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            view.setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View view, int i, KeyEvent keyEvent) {
                    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        switch (i) {
                            case KeyEvent.KEYCODE_ENTER:
                                iMode.getMode(1);
                                dismiss();
                                break;
                            case KeyEvent.KEYCODE_DPAD_CENTER:
                                iMode.getMode(1);
                                dismiss();
                                break;
                        }
                    }
                    return false;
                }
            });
        } else if (view.getId() == R.id.rlShowDetailCode) {
            if (SpUtil.getInstance(context).getBoolean(Constant.CODE_DETAIL, false)) {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.GONE);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon1.setVisibility(View.GONE);
                tvIcon1.setImageResource(R.mipmap.set_select_w);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_white));
            } else {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.VISIBLE);
                tvIcon.setImageResource(R.mipmap.set_select_y);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon1.setVisibility(View.GONE);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.IMG_IS_LOOP,false)){
                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.VISIBLE);
                tvIcon3.setImageResource(R.mipmap.set_select_y);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.GONE);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_white));
            }else{
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.VISIBLE);
                tvIcon2.setImageResource(R.mipmap.set_select_y);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.GONE);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.VIDEO_IS_LOOP,false)){
                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.VISIBLE);
                tvIcon5.setImageResource(R.mipmap.set_select_y);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.GONE);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_white));
            }else{
                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.VISIBLE);
                tvIcon4.setImageResource(R.mipmap.set_select_y);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.GONE);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            view.setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View view, int i, KeyEvent keyEvent) {
                    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        switch (i) {
                            case KeyEvent.KEYCODE_ENTER:
                                iMode.getMode(2);
                                dismiss();
                                break;
                            case KeyEvent.KEYCODE_DPAD_CENTER:
                                iMode.getMode(2);
                                dismiss();
                                break;
                        }
                    }
                    return false;
                }
            });
        } else if (view.getId() == R.id.rlImageStatic) {
            if (SpUtil.getInstance(context).getBoolean(Constant.CODE_DETAIL, false)) {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.GONE);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.VISIBLE);
                tvIcon1.setImageResource(R.mipmap.set_select_y);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_main));
            } else {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.VISIBLE);
                tvIcon.setImageResource(R.mipmap.set_select_y);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.GONE);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.IMG_IS_LOOP,false)){
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon2.setVisibility(View.GONE);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.VISIBLE);
                tvIcon3.setImageResource(R.mipmap.set_select_y);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_main));
            }else{
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon2.setVisibility(View.VISIBLE);
                tvIcon2.setImageResource(R.mipmap.set_select_w);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.GONE);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.VIDEO_IS_LOOP,false)){
                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.VISIBLE);
                tvIcon5.setImageResource(R.mipmap.set_select_y);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.GONE);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_white));
            }else{
                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.VISIBLE);
                tvIcon4.setImageResource(R.mipmap.set_select_y);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.GONE);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            view.setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View view, int i, KeyEvent keyEvent) {
                    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        switch (i) {
                            case KeyEvent.KEYCODE_ENTER:
                                iMode.getMode(3);
                                dismiss();
                                break;
                            case KeyEvent.KEYCODE_DPAD_CENTER:
                                iMode.getMode(3);
                                dismiss();
                                break;
                        }
                    }
                    return false;
                }
            });
        } else if (view.getId() == R.id.rlImageLoop) {
            if (SpUtil.getInstance(context).getBoolean(Constant.CODE_DETAIL, false)) {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.GONE);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.VISIBLE);
                tvIcon1.setImageResource(R.mipmap.set_select_y);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_main));
            } else {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.VISIBLE);
                tvIcon.setImageResource(R.mipmap.set_select_y);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.GONE);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.IMG_IS_LOOP,false)){
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.GONE);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon3.setVisibility(View.VISIBLE);
                tvIcon3.setImageResource(R.mipmap.set_select_w);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }else{
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.VISIBLE);
                tvIcon2.setImageResource(R.mipmap.set_select_y);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon3.setVisibility(View.GONE);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.VIDEO_IS_LOOP,false)){
                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.VISIBLE);
                tvIcon5.setImageResource(R.mipmap.set_select_y);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.GONE);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_white));
            }else{
                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.VISIBLE);
                tvIcon4.setImageResource(R.mipmap.set_select_y);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.GONE);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }
            view.setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View view, int i, KeyEvent keyEvent) {
                    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        switch (i) {
                            case KeyEvent.KEYCODE_ENTER:
                                iMode.getMode(4);
                                dismiss();
                                break;
                            case KeyEvent.KEYCODE_DPAD_CENTER:
                                iMode.getMode(4);
                                dismiss();
                                break;
                        }
                    }
                    return false;
                }
            });
        } else if (view.getId() == R.id.rlVideoStatic) {
            if (SpUtil.getInstance(context).getBoolean(Constant.CODE_DETAIL, false)) {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.GONE);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.VISIBLE);
                tvIcon1.setImageResource(R.mipmap.set_select_y);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_main));
            } else {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.VISIBLE);
                tvIcon.setImageResource(R.mipmap.set_select_y);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.GONE);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.IMG_IS_LOOP,false)){
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.GONE);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.VISIBLE);
                tvIcon3.setImageResource(R.mipmap.set_select_y);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_main));
            }else{
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.VISIBLE);
                tvIcon2.setImageResource(R.mipmap.set_select_y);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.GONE);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.VIDEO_IS_LOOP,false)){
                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon4.setVisibility(View.GONE);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.VISIBLE);
                tvIcon5.setImageResource(R.mipmap.set_select_y);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_main));

            }else{
                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon4.setVisibility(View.VISIBLE);
                tvIcon4.setImageResource(R.mipmap.set_select_w);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon5.setVisibility(View.GONE);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }
            view.setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View view, int i, KeyEvent keyEvent) {
                    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        switch (i) {
                            case KeyEvent.KEYCODE_ENTER:
                                iMode.getMode(5);
                                dismiss();
                                break;
                            case KeyEvent.KEYCODE_DPAD_CENTER:
                                iMode.getMode(5);
                                dismiss();
                                break;
                        }
                    }
                    return false;
                }
            });
        } else if (view.getId() == R.id.rlVideoLoop) {
            if (SpUtil.getInstance(context).getBoolean(Constant.CODE_DETAIL, false)) {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.GONE);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.VISIBLE);
                tvIcon1.setImageResource(R.mipmap.set_select_y);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_main));
            } else {
                rlHideDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon.setVisibility(View.VISIBLE);
                tvIcon.setImageResource(R.mipmap.set_select_y);
                tvHide.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlShowDetailCode.setBackgroundResource(R.drawable.bg_setting);
                tvIcon1.setVisibility(View.GONE);
                tvShow.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.IMG_IS_LOOP,false)){
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.GONE);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.VISIBLE);
                tvIcon3.setImageResource(R.mipmap.set_select_y);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_main));
            }else{
                rlImageStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon2.setVisibility(View.VISIBLE);
                tvIcon2.setImageResource(R.mipmap.set_select_y);
                tvImageStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlImageLoop.setBackgroundResource(R.drawable.bg_setting);
                tvIcon3.setVisibility(View.GONE);
                tvImageLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            if(SpUtil.getInstance(context).getBoolean(Constant.VIDEO_IS_LOOP,false)){
                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.GONE);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_white));

                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon5.setVisibility(View.VISIBLE);
                tvIcon5.setImageResource(R.mipmap.set_select_w);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_white));

            }else{
                rlVideoStatic.setBackgroundResource(R.drawable.bg_setting);
                tvIcon4.setVisibility(View.VISIBLE);
                tvIcon4.setImageResource(R.mipmap.set_select_y);
                tvVideoStatic.setTextColor(context.getResources().getColor(R.color.stage_main));

                rlVideoLoop.setBackgroundResource(R.drawable.bg_setting_select);
                tvIcon5.setVisibility(View.GONE);
                tvVideoLoop.setTextColor(context.getResources().getColor(R.color.stage_white));
            }

            view.setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View view, int i, KeyEvent keyEvent) {
                    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        switch (i) {
                            case KeyEvent.KEYCODE_ENTER:
                                iMode.getMode(6);
                                dismiss();
                                break;
                            case KeyEvent.KEYCODE_DPAD_CENTER:
                                iMode.getMode(6);
                                dismiss();
                                break;
                        }
                    }
                    return false;
                }
            });
        }
    }

    public interface IMode {
        void getMode(int mode);
    }
}
